import openai
import json

import requests

openai.api_key = "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"
model_engine = "gpt-3.5-turbo"  # or any other GPT-3.5 model
print("请输入问题")
prompt = input()
temperature = 0.7
max_tokens = 200
n = 1
stop = ["\n"]

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer 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'
}
a=[]
data = {
    "model": model_engine,
    "temperature": temperature,
    "max_tokens": max_tokens,
    "n": n,
    "messages": [{"role": "user", "content": prompt}]


}
print(data)
proxies = {
    'http': 'http://127.0.0.1:7890/',
    'https': 'http://127.0.0.1:7890/'
}
#
#https://api.openai.com/v1/models
#https://api.openai.com/v1/engines/davinci-codex/completions
# 发送POST请求
response = requests.post('https://api.openai.com/v1/chat/completions', headers=headers, json=data, proxies=proxies)
print("Response:"+str(response.json()))

print("response:"+response.json()['choices'][0]['message']['content'])